library(tidyverse) # for data cleaning and plotting
library(googlesheets4) # for reading googlesheet data
library(lubridate) # for date manipulation
library(openintro) # for the abbr2state() function
library(palmerpenguins)# for Palmer penguin data
library(maps) # for map data
library(ggmap) # for mapping points on maps
library(gplots) # for col2hex() function
library(RColorBrewer) # for color palettes
library(sf) # for working with spatial data
library(leaflet) # for highly customizable mapping
library(ggthemes) # for more themes (including theme_map())
library(plotly) # for the ggplotly() - basic interactivity
library(gganimate) # for adding animation layers to ggplots
library(transformr) # for "tweening" (gganimate)
library(shiny) # for creating interactive apps
library(gifski)
library(ggridges)
library(ggimage)
library(gganimate)
gs4_deauth() # To not have to authorize each time you knit.
theme_set(theme_minimal())
# SNCF Train data
small_trains <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-02-26/small_trains.csv")
# Lisa's garden data
garden_harvest <- read_sheet("https://docs.google.com/spreadsheets/d/1DekSazCzKqPS2jnGhKue7tLxRU3GVL1oxi-4bEM5IWw/edit?usp=sharing") %>%
mutate(date = ymd(date))
# Lisa's Mallorca cycling data
mallorca_bike_day7 <- read_csv("https://www.dropbox.com/s/zc6jan4ltmjtvy0/mallorca_bike_day7.csv?dl=1") %>%
select(1:4, speed)
# Heather Lendway's Ironman 70.3 Pan Am championships Panama data
panama_swim <- read_csv("https://raw.githubusercontent.com/llendway/gps-data/master/data/panama_swim_20160131.csv")
panama_bike <- read_csv("https://raw.githubusercontent.com/llendway/gps-data/master/data/panama_bike_20160131.csv")
panama_run <- read_csv("https://raw.githubusercontent.com/llendway/gps-data/master/data/panama_run_20160131.csv")
#COVID-19 data from the New York Times
covid19 <- read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv")
ggplotly() function.Weight_of_vegetables <- garden_harvest %>%
mutate(wt_lbs = weight*0.00220462) %>%
ggplot(aes(x = date , y = wt_lbs)) +
scale_y_continuous(n.breaks = 7) +
theme(panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()) +
geom_point(color = 'green') +
labs(title = "Weight of vegetables(lbs) over time(months)",
x = "",
y = "") +
geom_smooth(se = FALSE, color = 'dark blue')
ggplotly(Weight_of_vegetables,
tooltip = c("text", "x"))
veggie_harvest <- garden_harvest %>%
group_by(vegetable) %>%
summarize(total_wt_lbs = sum(weight)*0.00220462) %>%
ggplot() +
geom_col(aes(x = total_wt_lbs,
y = fct_reorder(vegetable,
total_wt_lbs,
.desc = FALSE),
text = vegetable)) +
labs(title = "Total Harvest by vegetable (lb)",
x = "Count",
y = "")
ggplotly(veggie_harvest,
tooltip = c("text", "x"))
small_trains dataset that contains data from the SNCF (National Society of French Railways). These are Tidy Tuesday data! Read more about it here.delay_small_trains <- small_trains %>%
group_by(service) %>%
filter(!is.na(service)) %>%
filter(departure_station %in% c("PARIS EST", "PARIS LYON"))
delay3 <- delay_small_trains %>%
ggplot(aes(x = avg_delay_all_departing,
y = service)) +
geom_density_ridges() +
transition_states(year) +
labs(title = "departing delay by French train services",
x = "Average delay for departing drains in minutes",
y = "train service",
subtitle = "Moving to {next_state}")
anim_save("trains2.gif", delay3)
knitr::include_graphics("trains2.gif")
geom_area() examples here). You will look at cumulative harvest of tomato varieties over time. You should do the following:garden_harvest data, filter the data to the tomatoes and find the daily harvest in pounds for each variety.fct_reorder()) from most to least harvested (most on the bottom).I have started the code for you below. The complete() function creates a row for all unique date/variety combinations. If a variety is not harvested on one of the harvest dates in the dataset, it is filled with a value of 0.
garden_harvest %>%
filter(vegetable == "tomatoes") %>%
complete(variety, date = seq.Date(min(date), max(date), by="day")) %>%
select(-c(vegetable, units)) %>%
mutate(weight = replace_na(weight, 0)) %>%
group_by(variety, date) %>%
summarize(daily_harvest_lb = sum(weight)*0.00220462) %>%
mutate(cumsum_daily_harvest_lb = cumsum(daily_harvest_lb)) %>%
select(-daily_harvest_lb) %>%
ggplot() +
geom_area(aes(x = date, y = cumsum_daily_harvest_lb, fill = variety), position = position_stack()) +
transition_reveal(date) +
labs(title = "Cumulative Harvest of Varieties of Tomatoes through Time",
x = "Date",
y = "Cumulative Daily Harvest",
subtitle = "Moving to {frame_along}")
anim_save("harvest_area.gif")
knitr::include_graphics("harvest_area.gif")
mallorca_bike_day7 bike ride using animation! Requirements:ggmap.ggimage package and geom_image to add a bike image instead of a red point. You can use this image. See here for an example.bike_image_link <- "https://raw.githubusercontent.com/llendway/animation_and_interactivity/master/bike.png"
mallorca_bike_day7 <- mallorca_bike_day7 %>%
mutate(image = bike_image_link)
mallorca_map <- get_stamenmap(
bbox = c(left = 2.28, bottom = 39.41, right = 3.03, top = 39.8),
maptype = "terrain",
zoom = 12
)
ggmap(mallorca_map) +
geom_point(data = mallorca_bike_day7,
aes(x = lon, y = lat),
color = "red", size = .5) +
geom_path(data = mallorca_bike_day7,
aes(x = lon, y = lat, color = ele),
size = .7) +
labs(title = "Mallorca Bike Trail",
subtitle = "Time: {frame_along}") +
geom_image(data = mallorca_bike_day7,
aes(x = lon, y = lat, image = bike_image_link),
size = 0.075) +
transition_reveal(time) +
scale_color_viridis_c(option = "magma") +
theme_map() +
theme(legend.background = element_blank())